package com.zprmb.udzt.adapter;

import java.text.DecimalFormat;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zprmb.udzt.R;
import com.zprmb.udzt.bean.Myexgold;
import com.zprmb.udzt.util.Regular;

public class Ex_gold_Adapter extends BaseAdapter {
	private Context context;
	private List<Myexgold> list;
	DecimalFormat df2 = new DecimalFormat("###0.00");
 
	public Ex_gold_Adapter(Context context, List<Myexgold> list) {
		super();
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Help h=null;
		if(convertView==null){
			h=new Help();
			convertView=LayoutInflater.from(context).inflate(R.layout.ex_gold_item, null);
			h.tv_amount=(TextView)convertView.findViewById(R.id.amount);
			h.tv_arrivetime=(TextView)convertView.findViewById(R.id.tv_forecast);
			h.tv_createtime=(TextView)convertView.findViewById(R.id.tv_arrivetime);
			h.tv_due=(TextView)convertView.findViewById(R.id.dueinterest);
            h.tv_status=(TextView)convertView.findViewById(R.id.tv_status);
            h.rl_bg=(RelativeLayout)convertView.findViewById(R.id.rl_bg);
            convertView.setTag(h);
			
		}else{
			h=(Help) convertView.getTag();
		}
		h.tv_amount.setText("¥"+df2.format(Double.parseDouble(list.get(position).getExpAmount())));
		h.tv_arrivetime.setText(Regular.getMilliToDate2(list.get(position).getExpArriveTime())+"收益到账");
		h.tv_createtime.setText(Regular.getMilliTotime3(list.get(position).getCreateTime())+"获得"+list.get(position).getExpName());
		h.tv_due.setText("+"+df2.format(Double.parseDouble(list.get(position).getDueInterest())));
		h.tv_status.setText(list.get(position).getExpState());
		if(list.get(position).getExpState().equals("ARRIVAL")){
			list.get(position).setStatus(true);
		}else{
			list.get(position).setStatus(false);
		}
		if(list.get(position).isStatus()){
			h.tv_status.setText("已收");
			h.rl_bg.setBackgroundResource(R.drawable.ex_2bg);
			h.tv_amount.setTextColor(Color.parseColor("#68819c"));
			h.tv_status.setBackgroundColor(Color.parseColor("#384c62"));
			h.tv_due.setText("+"+df2.format(Double.parseDouble(list.get(position).getReceivedInterest())));
		}else{
			h.tv_status.setText("待收");
			h.tv_status.setBackgroundColor(Color.parseColor("#E86b02"));
			h.tv_due.setText("+"+df2.format(Double.parseDouble(list.get(position).getDueInterest())));
			h.rl_bg.setBackgroundResource(R.drawable.ex_bg);
			h.tv_amount.setTextColor(Color.parseColor("#ff8c2a"));
		}
		return convertView;
	}
	private  static class Help{
		private TextView tv_amount,tv_due,tv_status,tv_createtime,tv_arrivetime;
		private RelativeLayout rl_bg;
	}

}
